package com.lwj.service.configuration;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.lwj.dto.configuration.AttConfigurationDto;
import com.lwj.dto.configuration.AttConfigurationListDto;
import com.lwj.mapper.configuration.AttConfigurationMapper;
import com.lwj.model.configuration.AttConfiguration;
import com.lwj.service.DozerService;
import com.lwj.vo.PageBean;
import com.lwj.vo.configuration.AttConfigurationVo;
import com.lwj.vo.system.DictionaryCategoryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class AttConfigurationServiceImpl implements AttConfigurationService {
    @Autowired
    private AttConfigurationMapper attConfigurationMapper;
    @Autowired
    private DozerService dozerService;
    @Override
    public int deleteByPrimaryKey(String attConfigurationId) {
        return attConfigurationMapper.deleteByPrimaryKey(attConfigurationId);
    }

    @Override
    public int insert(AttConfiguration record) {
        return attConfigurationMapper.insert(record);
    }

    @Override
    public int insertSelective(AttConfiguration record) {
        return attConfigurationMapper.insertSelective(record);
    }

    @Override
    @Transactional
    public AttConfiguration selectByPrimaryKey(String attConfigurationId) {
        return attConfigurationMapper.selectByPrimaryKey(attConfigurationId);
    }

    @Override
    public int updateByPrimaryKeySelective(AttConfiguration record) {
        return attConfigurationMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(AttConfiguration record) {
        return attConfigurationMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageBean<AttConfigurationVo> list(AttConfigurationListDto dto) {
        Page<AttConfigurationVo> objects = PageHelper.startPage(dto.getPageNumber(), dto.getPageSize());
        attConfigurationMapper.list(dto);
        return PageBean.page(objects);
    }

    @Override
    public String save(AttConfigurationDto dto) {
        AttConfiguration map = dozerService.map(dto, AttConfiguration.class);
        if(StringUtils.hasText(map.getAttConfigurationId())){
            attConfigurationMapper.updateByPrimaryKeySelective(map);
        }else {
            attConfigurationMapper.insertSelective(map);
        }
        return map.getAttConfigurationId();
    }

    @Override
    public AttConfigurationVo select(String attConfigurationId) {
        return attConfigurationMapper.select(attConfigurationId);
    }

}
